<?php
require_once dirname(__FILE__)  . '/../libs/AuthenInterface.php';

require_once 'PHPUnit/Framework.php';
require_once 'Log.php';

class AuthenInterfaceTest extends PHPUnit_Framework_TestCase
{
    private $_logger;
    private $_interface;
    
    protected function setUp()
    {
        $logger = Log::factory('console', '', '', array(), PEAR_LOG_INFO);
        $this->_logger = $logger;
        $this->_interface = new AuthenInterface(AuthenInterface::APP_ENV_TEST);
    }
    
    protected function tearDown()
    {
        
    }
    
    public function testOpen()
    {
		$this->markTestSkipped();
        $arr = array(
        	'appId'=>112233,
          	'app'=>array( 'appName'=>'应用名称', 'test'=>1),
          	'cas'=>array('domain'=>'www.kingwhy.com', 'isSelf'=>false)
          );
        $result = $this->_interface->open($arr, 2);
        print_r($this->_interface->getErrMsg()."||".$this->_interface->getErrNo());
        $this->assertTrue($result !== false);        
        return $result;
    }
    
    public function testClose()
    {
        $this->markTestSkipped();
        $arr = array(
            'appId'=>112233,
          	'cas'=>array('domain'=>array('www.kingwhy.com','www.xingqinhua.com'))
          );
        $result = $this->_interface->close( $arr, 2);
        $this->assertTrue($result !==false);
        print_r($this->_interface->getErrMsg()."||".$this->_interface->getErrNo());
        return $result;
    }
    
    public function testUpdate()
    {
        $this->markTestSkipped();
        $arr = array(
        	'appId'=>112233,
          	'app'=>array( 'appName'=>'应用名称', 'test'=>2),
            'appStatus'=>array('test'=>AuthenInterface::AUTHEN_STATUS_ONLINE),
          	'cas'=>array('domain'=>array('www.xingqinhua.com','www.kingwhy.com'), 'isSelf'=>true)
          );
        $result = $this->_interface->update( $arr, AuthenInterface::APP_ENV_PRODUCTION);        
        $this->assertTrue($result !== false);
        print_r($this->_interface->getErrMsg()."||".$this->_interface->getErrNo());
        return $result;
    }
    
    public function testSync()
    {
        $this->markTestSkipped();
        $arr = array(
        	'appId'=>112233,
          	'testAccounts'=>array( 
                array('op'=>AuthenInterface::TEST_ACCOUNTS_ADD, 'account'=>'mobfan', 'areaId'=>0),
                array('op'=>AuthenInterface::TEST_ACCOUNTS_DELETE, 'account'=>'mobfan', 'areaId'=>1),
             ),
            'trustIp'=>array(
                array('ip'=>'127.0.0.1','areaId'=>1,'groupId'=>1, 'op'=>AuthenInterface::TRUST_IP_DELETE)
            ),
            'cas'=>array(
	            'domain'=>array(
		            array('domain'=>'www.xingqinhua.com', 'op'=>0),
		            array('domain'=>'www.kingwhy.com', 'op'=>1)
	            ), 
	            'isSelf'=>true
            )
          );
        $result = $this->_interface->sync( $arr, AuthenInterface::APP_ENV_PRODUCTION);
        $this->assertTrue($result !== false);
        print_r($this->_interface->getErrMsg()."||".$this->_interface->getErrNo());
        return $result;
    }
    
    public function testGet()
    {
//        $this->markTestSkipped();
        $arr = array(
        	'appId'=>112233,
            'cas'=>array('www.kingwhy.com')
          );
        $result = $this->_interface->get( $arr, AuthenInterface::APP_ENV_PRODUCTION);
        $this->assertTrue($result !== false);
        print_r($this->_interface->getErrMsg()."||".$this->_interface->getErrNo());
        print_r($result);
        return $result;
    }
}
